package com.qf.swagger.utils;

import com.qf.swagger.config.Swaggerproperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

public class SwaggerAppender {

    @Bean
    public Docket buildDocket(Swaggerproperties swaggerproperties){
        final Docket docket = new Docket(DocumentationType.SWAGGER_2);
        docket.apiInfo(getApiInfo(swaggerproperties)).select().apis(RequestHandlerSelectors.basePackage(swaggerproperties.getBasepackage())).build();

        return docket;
    }

    private ApiInfo getApiInfo(Swaggerproperties swaggerproperties) {
        return new ApiInfoBuilder().contact(new Contact("千锋教育","http://www.baidu.com","wenhualiu340@gmail.com"))
                .title(swaggerproperties.getTitle())
                .version(swaggerproperties.getVersion())
                .description(swaggerproperties.getBasepackage())
                .build();
    }
}
